From 2a0e3293409c93e71d839a94577cfab439f06c1b Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Wed, 23 Dec 2020 11:24:07 -0600 Subject: [PATCH] Handle multiple errors from a get_data or factory or cleanup --- src/pgwui_core/core.py | 14 ++++++++++++++ src/pgwui_core/exceptions.py | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/src/pgwui_core/core.py b/src/pgwui_core/core.py index f4cc3f9..6f60d67 100644 --- a/src/pgwui_core/core.py +++ b/src/pgwui_core/core.py @@ -1046,6 +1046,10 @@ class DBHandler(object): (Post-processing is referred to as "cleanup" presently.) Rendering the html output + The get_data, factory, and cleanup have two possible ways to report errors. + They can raise an exception or raise the "special" exception + MultiError. + Attributes: request A pyramid request instance uf An UploadForm instance @@ -1076,6 +1080,8 @@ class DBHandler(object): ''' Validate input needed beyond that required to connect to the db. + Returns a list of exceptions + Note that this occurs after read() is called. This is expected to be replaced by it's subclass. @@ -1104,6 +1110,9 @@ class DBHandler(object): ''' Called after all lines are processed to do any final updates to the db. + + May raise a single exception or may save multiple exceptions + and raise MultiError. ''' pass @@ -1175,6 +1184,7 @@ class UploadHandler(SessionDBHandler): ''' Takes an UploadEngine instance Returns a DataLineProcessor instance + May raise a single exception or MultiError. ''' raise NotImplementedError @@ -1411,6 +1421,8 @@ class DBConnector(object): # (Cannot call uh until after self is fully # initalized, including self.cur.) processor = self.uh.factory(self) + except core_ex.MultiError as ex: + errors.extend(ex.errors) except core_ex.Error as ex: errors.append(ex) else: @@ -1419,6 +1431,8 @@ class DBConnector(object): # Let upload handler finish try: self.uh.cleanup() + except core_ex.MultiError as ex: + errors.extend(ex.errors) except core_ex.UploadError as ex: errors.append(ex) finally: diff --git a/src/pgwui_core/exceptions.py b/src/pgwui_core/exceptions.py index 1d92031..dc89a4c 100644 --- a/src/pgwui_core/exceptions.py +++ b/src/pgwui_core/exceptions.py @@ -30,6 +30,13 @@ class PGWUIError(Exception): pass +class MultiError(PGWUIError): + '''Multiple errors + ''' + def __init__(self, errors): + self.errors = errors + + class UploadError(PGWUIError): ''' Module exceptions are derived from this class. -- 2.34.1